/*
 * Globals.java
 *
 * Created on April 12, 2006, 3:26 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package main;

import dao.filesystem.FilesDAOFactory;
import dao.sql.HsqldbDAOFactory;
import facade.AppFacade;
import facade.AppFacadeImpl;
import main.controller.actions.observer.AbstractObserverAction;

import java.util.HashSet;
import java.util.Set;

/**
 * @author root
 */
public class Main {

    private static Main instance;

    /**
     * @return the instance
     */
    public static Main getInstance() {
        return instance;

    }

    private AppFacade appFacade;
    Set<AbstractObserverAction> observerActions = new HashSet<AbstractObserverAction>();

    /**
     * Creates a new instance of Main
     */
    private Main(DataResourceType dataResource) throws Exception {
        instance = this;
        switch (dataResource) {
            case SQL:
                appFacade = new AppFacadeImpl(new HsqldbDAOFactory());
                break;
            case FILE_SYSTEM:
                appFacade = new AppFacadeImpl(new FilesDAOFactory());
                break;

        }

    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {

        DataResourceType dataResource;
//        if (args.length > 0 && "sql".startsWith(args[0])) {
//            dataResource = DataResourceType.SQL;
//        } else {
//            dataResource = DataResourceType.FILE_SYSTEM;
//        }
        dataResource = DataResourceType.FILE_SYSTEM;

        new Main(dataResource);
        MainFrame.getInstance();
    }

    public void addObserverAction(AbstractObserverAction action) {
        observerActions.add(action);
    }

    public void fireStateChanged() {
        for (AbstractObserverAction action : observerActions) {
            action.applicationStateChanged();
        }
    }

    public AppFacade getFacade() {
        return appFacade;
    }

}